package kr.hkit.powerjava.chapter25;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

public class URLPostTest {
	public static void main(String[] args) {
		//http://hkit.kr/SUB/?ctId=22
		try {
			URL url = new URL("http://hkit.kr/SUB/");
			URLConnection connection = url.openConnection();	//커넥션 열기
			connection.setDoOutput(true);//요청을 보내겠다.
				
			OutputStreamWriter out = new OutputStreamWriter(connection.getOutputStream());
			out.write("ctId=" + 22);
			out.close();
			
			BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
			String line;
			while((line = in.readLine()) != null) { //한줄씩 읽어옴 널이 되면 마지막임
				System.out.println(line);
			}
			in.close();
			
			
		} catch (MalformedURLException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
